//
//  ViewController.m
//  rockpaperscissors
//
//  Created by iD Student on 7/23/13.
//  Copyright (c) 2013 idstudent. All rights reserved.


#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.

    NSURL *url = [[NSBundle mainBundle] URLForResource:@"rock" withExtension:@"mp3"];
    NSError *error;
   rockSound = [[AVAudioPlayer alloc] initWithContentsOfURL: url error: &error];
    if(error != nil)
    {
        //This happens when the sound cannot be loaded
        NSLog(@"Rock sound could not be loaded!");
    }
    
    url = [[NSBundle mainBundle] URLForResource:@"paper" withExtension:@"mp3"];
    error= nil;
    paperSound = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:&error];
    if(error != nil)
    {
        //This happens when the sound cannot be loaded
        NSLog(@"Paper sound could not be loaded!");}
    
    
    url = [[NSBundle mainBundle] URLForResource:@"scissors" withExtension:@"mp3"];
    error = nil;
    scissorsSound = [[AVAudioPlayer alloc] initWithContentsOfURL: url error: &error];
    if(error != nil)
    {
        //This happens when the sound cannot be loaded
        NSLog(@"scissors sound could not be loaded!");
    }
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)show_rock2:(id)sender 
{
    [rockSound play];
    player_image.image = [UIImage imageNamed: @"imgres.jpeg"];
    int computeraction= arc4random() %3;
    if (computeraction== 1)
    {
    opponent_image.image = [UIImage imageNamed: @"imgres.jpeg"];
    }
    else if(computeraction== 2)
    {
    opponent_image.image = [UIImage imageNamed: @"imgres-2.jpeg"];
    }
    else if (computeraction== 0)
    {
    opponent_image.image = [UIImage imageNamed: @"imgres-1.jpeg"];
    }
    
    if (computeraction ==1)
    {
        tie++;
        ties.text=[[NSString alloc] initWithFormat:@"TIES:%d",tie ];
    }
    else if (computeraction==2)
    {
        loss++;
        losses.text=[[NSString alloc] initWithFormat:@"LOSSES:%d",loss ];    }
    else if (computeraction==0)
    {
        win++;
        wins.text=[[NSString alloc] initWithFormat:@"WINS:%d",win ];
    }
}
- (IBAction)show_paper2:(id)sender
{
    [paperSound play];
    player_image.image = [UIImage imageNamed: @"imgres-2.jpeg"];
    int computeraction= arc4random() %3;
    if (computeraction== 1)
    {
        opponent_image.image = [UIImage imageNamed: @"imgres.jpeg"];
    }
    else if(computeraction== 2)
    {
        opponent_image.image = [UIImage imageNamed: @"imgres-2.jpeg"];
    }
    else if (computeraction== 0)
    {
        opponent_image.image = [UIImage imageNamed: @"imgres-1.jpeg"];
    }
    if (computeraction ==1)
    {
        win++;
        wins.text=[[NSString alloc] initWithFormat:@"WINS:%d",win ];
    }
    else if (computeraction==2)
    {
        tie++;
        ties.text=[[NSString alloc] initWithFormat:@"TIES:%d",tie ];
    }
    else if (computeraction==0)
    {
        loss++;
        losses.text=[[NSString alloc] initWithFormat:@"LOSSES:%d",loss ];
    }
}

- (IBAction)show_scissors2:(id)sender
{
    [scissorsSound play];
    player_image.image = [UIImage imageNamed: @"imgres-1.jpeg"];
    int computeraction= arc4random() %3;
    if (computeraction== 1)
    {
        opponent_image.image = [UIImage imageNamed: @"imgres.jpeg"];
    }
    else if(computeraction== 2)
    {
        opponent_image.image = [UIImage imageNamed: @"imgres-2.jpeg"];
    }
    else if (computeraction== 0)
    {
        opponent_image.image = [UIImage imageNamed: @"imgres-1.jpeg"];
    }
    if (computeraction ==1)
    {
        loss++;
        losses.text=[[NSString alloc] initWithFormat:@"LOSSES:%d",loss ];
    }
    else if (computeraction==2)
    {
        win++;
        wins.text=[[NSString alloc] initWithFormat:@"WINS:%d",win ];
    }
    else if (computeraction==0)
    {
        tie++;
        ties.text=[[NSString alloc] initWithFormat:@"TIES:%d",tie ];
    }
}



@end